<?php
namespace app\api\controller;

use app\home\model\Images;

class Active
{
    public function index()
    {
        return json(Images::where('image_kind', 4)->select());
    }

    public function add()
    {
        $data = request()->param();
        $data['image_kind'] = 4;
        $active = new Images;
        $active->save($data);
        return json([
            'active'=>Images::find($active->id),
        ]);
    }

    public function edit()
    {
        $data = request()->param();
        $active = Images::find($data['id']);
        $active->save([
            'image'=>$data['image'],
            'image_url'=>$data['image_url']
        ]);
        return json(true);
    }

    public function del()
    {
        $data = request()->param();
        return json(
            Images::destroy($data['id'])
        );
    }
}
